﻿@using PagedList
@model PagedList.IPagedList<TaoNiuOA.Models.Task>
@{
    ViewBag.Title = "任务管理";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
    var currentMod = ViewBag.mod;
}
<script type="text/javascript">
    function showLevel(obj) {
        switch (obj) {
            case 0:
                document.write("低");
                break;
            case 1:
                document.write("普通");
                break;
            case 2:
                document.write("高");
                break;
            default:
                document.write("紧急");
        }
    }

    function showStatus(obj) {
        switch (obj) {
            case 0:
                document.write("未被领取");
                break;
            case 1:
                document.write("已被领取");
                break;
            case 2:
                document.write("执行中");
                break;
            default:
                document.write("已完成");
        }
    }
</script>
<fieldset>
    <legend><a href="/Task/index">任务管理</a> | 审批任务 | <a href="/TaskType/index">类型管理</a></legend>
    <br />
    <table>
        <tr>
            <th>
                名称
            </th>
            <th>
                类型
            </th>
            <th>
                发布时间
            </th>
            <th>
                绩效
            </th>
            <th>
                任务期限
            </th>
            <th>
                级别
            </th>
            <th>
                进度
            </th>
            <th>
                开始时间
            </th>
            <th>
                结束时间
            </th>
            <th>
                已持续天数
            </th>
            <th>
                状态
            </th>
            <th>
                最后更新
            </th>
            <th>
                负责人
            </th>
            <th>
                操作
            </th>
        </tr>
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.Name)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.GetTaskType().TypeName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.PubTime)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Point)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.ProjectLast)
                </td>
                <td>
                    <script>showLevel(@item.Level)</script>
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Process)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.StartTime)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.EndTime)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.LastDays)
                </td>
                <td>
                    <script>showStatus(@item.Status)</script>
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.LastUpdate)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.GetUser().GetUserInfo().Name)
                </td>
                <td>
                    <a href="/task/details/@item.TaskID">详细</a> | <a href="javascript:popshow(@item.TaskID);">
                        编辑</a>
                </td>
            </tr>
        }
    </table>
    <div style="width: auto; height: 30px; margin-top: 20px; text-align: center;">
        @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber)
        / @Model.PageCount
        &nbsp;
        @if (Model.HasPreviousPage)
        {
            @Html.ActionLink("首页", "MyTask", new { mod = currentMod, page = 1, currentFilter = ViewBag.CurrentFilter })
            @Html.Raw("&nbsp;");
            @Html.ActionLink(" 上一页", "MyTask", new { mod = currentMod, page = Model.PageNumber - 1, currentFilter = ViewBag.CurrentFilter })
        }
        else
        {
            @:首页
        @Html.Raw("&nbsp;");
            @:上一页
                                                                                                                                                                                                                                            }
        &nbsp;
        @if (Model.HasNextPage)
        {
            @Html.ActionLink("下一页 ", "MyTask", new { mod = currentMod, page = Model.PageNumber + 1, currentFilter = ViewBag.CurrentFilter })
            @Html.Raw("&nbsp;");
            @Html.ActionLink("尾页", "MyTask", new { mod = currentMod, page = Model.PageCount, currentFilter = ViewBag.CurrentFilter })
        }
        else
        {
            @:下一页
        @Html.Raw("&nbsp;")
            @:尾页
                                                                                                                                                                                                                                 }
    </div>
</fieldset>
<script src="../../Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
<link href="../../Plusins/jQtip/jqTip.css" rel="stylesheet" type="text/css" />
<div>
    <div id="popupText">
        <h1>
            审批任务
        </h1>
        <div id="textArea">
            <form id="popupForm" action="" method="post">
            <div id="popupMain" style="text-align: center;">
            </div>
            <br />
            <br />
            <div style="text-align: center;">
                <input type="button" value="确定" id="popSubmit" />
                <input type="button" value="取消" id="popCancel" />
            </div>
            </form>
        </div>
    </div>
    <div id="backgroundPopup">
    </div>
</div>
<script type="text/javascript">

    //打开弹出窗口
    //按钮点击事件
    var taskID = 0;
    function popshow(obj) {
        //设置弹出层的大小
        taskID = obj;
        $("#popupText").css({ height: "280", width: "250" });
        $.post("ShowApproveTask/" + obj, function (data) {
            $("#popupMain").html(data);
        });
        //调用函数居中窗口
        centerPopup();
        //调用函数加载窗口
        loadPopup();
    }

    //初始化：是否开启DIV弹出窗口功能
    //0 表示开启; 1 表示不开启;
    var popupStatus = 0;
    //使用Jquery加载弹窗 
    function loadPopup() {
        //仅在开启标志popupStatus为0的情况下加载  
        if (popupStatus == 0) {
            $("#backgroundPopup").css({
                "opacity": "0.7"
            });
            $("#backgroundPopup").fadeIn("slow");
            $("#popupText").fadeIn("slow");
            popupStatus = 1;
        }
    }
    //使用Jquery去除弹窗效果 
    function disablePopup() {
        //仅在开启标志popupStatus为1的情况下去除
        if (popupStatus == 1) {
            $("#backgroundPopup").fadeOut("slow");
            $("#popupText").fadeOut("slow");
            popupStatus = 0;
        }
    }
    //将弹出窗口定位在屏幕的中央
    function centerPopup() {
        //获取系统变量
        var windowWidth = document.documentElement.clientWidth;
        var windowHeight = document.documentElement.clientHeight;
        var popupHeight = $("#popupText").height();
        var popupWidth = $("#popupText").width();
        //居中设置   
        $("#popupText").css({
            "position": "absolute",
            "top": windowHeight / 2 - popupHeight / 2,
            "left": windowWidth / 2 - popupWidth / 2
        });

        //以下代码仅在IE6下有效
        $("#backgroundPopup").css({
            "height": windowHeight
        });
    }

    //确定
    $("#popSubmit").click(function () {
        var isGood = $("#IsGood").val();
        var point = $("#taskPoint").val();
        var remark = $("#remark").val();
        if (isGood) {
            $.post("approveTask?IsGood=" + isGood + "&taskID=" + taskID + "&taskPoint=" + point+"&remark="+remark, function (data) {
                if (data == "ok") {
                    window.location.reload();
                    alert("编辑成功");
                }
                else
                    alert("编辑失败");
            });
        }
    });


    //取消
    $("#popCancel").click(function () {
        disablePopup();
    });
</script>
